<template>
  <div>
    <div class="container" @click="commentChange2()">
      <div class="right">
        <div class="card">
          <div class="myPhoto">
            <img class="myPhoto" src="../../assets/img/头像.png" alt="" />
          </div>
          <h2 class="nickname">男神味的果冻</h2>
          <div class="row">
            <div class="view">
              <h3 class="num">265</h3>
              <span>总访问量</span>
            </div>
            <div class="solution">
              <h3 class="num">5</h3>
              <span>答疑总数</span>
            </div>
          </div>
          <div class="row">
            <div class="fans">
              <h3 class="num">265</h3>
              <span>粉丝</span>
            </div>
            <div class="follow">
              <h3 class="num">5</h3>
              <span>关注</span>
            </div>
          </div>
          <div class="row">
            <router-link :to="{ name: 'Publish' }">
              <el-button type="primary" plain>私信</el-button>
            </router-link>
            <el-button type="success" plain>已关注</el-button>
          </div>
        </div>
      </div>
      <div class="show">
        <div>
          <h2>
            {{ article.title }}
          </h2>
        </div>
        <div class="datas">
          <div class="action">
            <div class="time" style="width: 240px">
              <span style="color: #999aaa"
                >已于 {{ article.updateTime }} 修改</span
              >
            </div>
            <div class="cow">
              <img src="../../assets/img/点赞 (off).png" alt="" />
              <span>点赞数 {{ article.likeCount }}</span>
            </div>
            <div class="cow">
              <img src="../../assets/img/收藏 (off).png" alt="" />
              <span>收藏 {{ article.collectCount }}</span>
            </div>
            <div class="cow">
              <img src="../../assets/img/浏览.png" alt="" />
              <span>阅读量 {{ article.visits }}</span>
            </div>
          </div>
          <div class="classify">
            <router-link
              :to="{ name: 'Search', params: { keyWord: article.boardName } }"
            >
              <span style="color: #4ea1db; font-size: 17px"
                >文章分类: {{ article.boardName }}</span
              >
            </router-link>
          </div>
        </div>
        <div class="head">
          <h4>
            {{ article.desc }}
          </h4>
        </div>
        <div class="content">
          <p>{{ article.content }}</p>
        </div>
        <div class="bottomNav">
          <div class="leftNav">
            <img src="../../assets/img/头像.png" alt="" />
            <span>{{ article.nickName }}</span>
            <el-button round>已关注</el-button>
          </div>
          <div class="rightNav">
            <div class="action">
              <div class="col" @click="changeImg()">
                <img src="../../assets/img/点赞 (off).png" alt="" id="zan" />
                <span>点赞数 {{ article.likeCount }}</span>
              </div>
              <div
                class="col"
                @click="changeImg1()"
                style="margin-left: 20px; width: 80px"
              >
                <img src="../../assets/img/踩.png" alt="" id="cai" />
                <span>踩</span>
              </div>
              <div class="col" @click="changeImg2">
                <img src="../../assets/img/收藏 (off).png" alt="" id="cang" />
                <span>收藏 {{ article.collectCount }}</span>
              </div>
              <div class="col" @click.stop="commentChange1()">
                <img src="../../assets/img/评论.png" alt="" />
                <span>评论数 {{ article.commentCount }}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <transition name="comment">
      <div class="comment" v-show="isshow">
        <div class="commentTotal">
          <span>评论 {{ article.commentCount }} </span>
          <img
            src="../../assets/img/错.png"
            alt=""
            @click="commentChange2()"
            style="width: 25px; height: 25px; margin-top: 25px; cursor: pointer"
          />
        </div>
        <div class="discuss">
          <img src="../../assets/img/头像.png" alt="" />
          <div class="commentData">
            <textarea
              id="commentContent"
              placeholder="对作者说点什么"
              maxlength="800"
              v-model="publishCommentContent"
            >
            </textarea>
            <el-button type="primary" round class="btn1" @click="postComment()"
              >发布评论</el-button
            >
          </div>
        </div>
        <div class="comments">
          <div
            class="commentsData"
            v-for="(comm, index) in comments"
            :key="comm.id"
          >
            <img src="../../assets/img/头像.png" alt="" />
            <div>
              <h4>王贝贝 {{ comm.createTime }}</h4>
              <div class="commentsContainer">
                <p>
                  {{ comm.commentContent }}
                </p>
              </div>
            </div>
            <img
              src="../../assets/img/点赞 (off).png"
              alt=""
              id="good"
              @click="changeImg3($event, comm.id)"
            />
          </div>
          <div class="page">
            <el-pagination
              @current-change="handleCurrentChange"
              :page-size="pageDto.pageSize"
              :current-page.sync="pageDto.curPage"
              layout="total, prev, pager, next"
              :total="totalPage"
            >
            </el-pagination>
          </div>
        </div>
      </div>
    </transition>
  </div>
</template>

<script>
import instance from "../../utils/request";
import { Message } from "element-ui";
export default {
  name: "NewDetails",
  mounted() {
    const id = this.$route.params.id;
    instance
      .get("article/get_info?id=" + id)
      .then((success) => {
        if (success.data.code == 10000) {
          this.article = success.data.data;
        } else {
          Message.error("数据出错啦，稍后再试");
        }
      })
      .catch((error) => {
        Message.error("系统出错啦，稍后再试");
        console.log(error);
      });
  },
  data() {
    return {
      article: {
        nickName: "陈亦康",
        id: 1,
        title: "大家帮我看看，我女儿到底有没有绘画天赋？",
        desc: "我的女儿！！！！！！别管你孩子有没有天赋了，先把这个班退了先。 且不说现在看不出什么天赋与才能，兴趣才是最好的的源动力，不能功利武断适得其… 快跑！！！！！！别管你孩子有没有天赋了，先把这个班退了先。 且不说现在看不出什么天赋与才能，兴趣才是最好的的源动力，不能功利武断适得其… 快跑！！！！！！别管你孩子有没有天赋了，先把这个班退了先。 且不说现在看不出什么天赋与才能，兴趣才是最好的的源动力，不能功利武断适得其… 快跑！！！",
        createTime: "2023-11-13 21:19:43",
        updateTime: "2023-11-13 22:00:00",
        boardName: "校园",
        visits: 8848,
        content:
          "它叫我输个名字： 快跑！！！！！！别管你孩子有没有天赋了，先把这个班退了先。 且不说现在看不出什么天赋与才能，兴趣才是最好的的源动力，不能功利武断适得其… 快跑！！！！！！别管你孩子有没有天赋了，先把这个班退了先。 且不说现在看不出什么天赋与才能，兴趣才是最好的的源动力，不能功利武断适得其… 快跑！！！！！！别管你孩子有没有天赋了，先把这个班退了先。 且不说现在看不出什么天赋与才能，兴趣才是最好的的源动力，不能功利武断适得其… 快跑！！！！！！别管你孩子有没有天赋了，先把这个班退了先。 且不说现在看不出什么天赋与才能，兴趣才是最好的的源动力，不能功利武断适得其… 快跑！！！！！！别管你孩子有没有天赋了，先把这个班退了先。 且不说现在看不出什么天赋与才能，兴趣才是最好的的源动力，不能功利武断适得其… 快跑！！！！！！别管你孩子有没有天赋了，先把这个班退了先。 且不说现在看不出什么天赋与才能，兴趣才是最好的的源动力，不能功利武断适得其…孩子有没有天赋了，先把这个班退了先。 且不说现在看不出什么天赋与才能，兴趣才是最好的的源动力，不能功利武断适得其… 快跑！！！！！！别管你孩子有没有天赋了，先把这个班退了先。 且不说现在看不出什么天赋与才能，兴趣才是最好的的源动力，不能功利武断适得其… 快跑！！！！！！别管你孩子有没有天赋了，先把这个班退了先。 且不说现在看不",
        likeCount: 4,

        commentCount: 8,
        collectCount: 21,
      },

      Id: this.$route.params.id,

      isshow: false,
      comments: [
        {
          id: 1,
          userId: 1,
          articleId: 1,
          commentContent: "博主写的还不错",
          createTime: "2023-11-14 23:58:37",
        },
        {
          id: 1,
          userId: 1,
          articleId: 1,
          commentContent: "博主写的还不错",
          createTime: "2023-11-14 23:58:37",
        },
        {
          id: 2,
          userId: 1,
          articleId: 1,
          commentContent: "博主写的不讨好",
          createTime: "2023-11-14 23:58:37",
        },
        {
          id: 3,
          userId: 1,
          articleId: 1,
          commentContent: "博主写的还不错",
          createTime: "2023-11-14 23:58:37",
        },
        {
          id: 4,
          userId: 1,
          articleId: 1,
          commentContent: "博主写的还不错",
          createTime: "2023-11-14 23:58:37",
        },
      ],
      publishCommentContent: "写的不哈",
      pageDto: {
        curPage: 1, //当前页
        //每页显示条数
        pageSize: 3,
      },
      //总条数
      totalPage: 0,
    };
  },

  methods: {
    //文章点赞
    changeImg() {
      const zan = document.querySelector("#zan");
      const imgurl1 = require("../../assets/img/点赞 (on).png");
      const imgurl2 = require("../../assets/img/点赞 (off).png");

      if (zan.className == "") {
        this.article.likeCount++;
        zan.src = imgurl1;
        zan.className = "after";
        instance
          .post("/article/like/play", this.Id)
          .then((success) => {
            if (success.data.code == 10000) {
            } else {
              Message.error("点赞版块出错了，请您稍后再试");
            }
          })
          .catch((error) => {
            Message.error("系统错了，稍后再试");
            console.log(error);
          });
      } else {
        (zan.className = ""), (zan.src = imgurl2);
        this.article.likeCount--;
      }
    },
    //不喜欢文章
    changeImg1() {
      const cai = document.querySelector("#cai");
      const imguil3 = require("../../assets/img/踩.png");
      const imguil4 = require("../../assets/img/踩1.png");
      if (cai.className == "") {
        this.article.unlikeCount++;
        cai.className = "after";
        cai.src = imguil4;
      } else {
        cai.className = "";
        cai.src = imguil3;
        this.article.unlikeCount--;
      }
    },
    //文章收藏
    changeImg2() {
      const cang = document.querySelector("#cang");
      const imguil5 = require("../../assets/img/收藏 (off).png");
      const imguil6 = require("../../assets/img/收藏 (on).png");
      if (cang.className == "") {
        this.article.collectCount++;
        cang.className = "after";
        cang.src = imguil6;
        instance
          .post("/article/collect/play", this.Id)
          .then((success) => {
            if (success.data.code == 10000) {
            } else {
              Message.error("收藏版块出错了，请您稍后再试");
            }
          })
          .catch((error) => {
            Message.error("系统错了，稍后再试");
            console.log(error);
          });
      } else {
        cang.src = imguil5;
        cang.className = "";
        this.article.collectCount--;
      }
    },
    //评论点赞
    changeImg3(e, commentid) {
      const imgurl1 = require("../../assets/img/点赞 (on).png");
      const imgurl2 = require("../../assets/img/点赞 (off).png");
      console.log(e.currentTarget);
      if (e.currentTarget.className == "") {
        e.currentTarget.src = imgurl1;
        e.currentTarget.className = "after";
        instance
          .post("")
          .then((success) => {
            if (success.data.code == 10000) {
            } else {
              Message.error("点赞版块出错了，请您稍后再试");
            }
          })
          .catch((error) => {
            Message.error("系统错了，稍后再试");
            console.log(error);
          });
      } else {
        (e.currentTarget.className = ""), (e.currentTarget.src = imgurl2);
      }
    },
    //评论区的显示与隐藏
    commentChange1() {
      this.isshow = true;
      instance
        .post(
          "/article/comment/page",
          {
            curpage: this.pageDto.curPage,
            pageSize: this.pageDto.pageSize,
            id: this.Id,
          }.then((success) => {
            if (success.data.code == 10000) {
              this.comments = success.data.list;
              this.totalPage = success.data.total;
            } else {
              Message.error("评论内容获取失败,请稍后再试");
            }
          })
        )
        .catch((error) => {
          Message.error("系统异常，请稍后再试");
          console.log(error);
        });
    },
    commentChange2() {
      this.isshow = false;
    },
    //发布评论
    postComment() {
      instance
        .post("/article/comment/add", {
          articleId: this.Id,
          content: this.publishCommentContent,
        })
        .then((success) => {
          if (success.data.code == 10000) {
            Message.success("发布成功");
          } else {
            Message.error("评论发布失败，请稍后再试");
          }
        })
        .catch((error) => {
          Message.error("系统出现错误，稍后再试");
          console.log(error);
        });
    },
  },
};
</script>

<style scoped>
.right .card {
  width: 100%;
  height: 100%;
  padding: 30px;
}

.right .card .myPhoto {
  width: 200px;
  height: 200px;
  border-radius: 10px;
  margin: 1px auto;
}

.right .card .nickname {
  width: 150px;
  height: 30px;
  margin: 10px auto;
}

.right .card .row {
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 20px 0;
}

.right .card .row .num {
  text-align: center;
  color: #222226;
  font-weight: 600;
  font-size: 20px;
}
.container .right {
  width: 300px;
  height: 560px;
  background-color: white;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  margin-top: 20px;
  min-width: 300px;
  margin-left: 100px;
}
.comment {
  width: 600px;
  height: 800px;
  background: white;
  z-index: 999;
  position: fixed;
  top: 0px;
  right: 0%;
  overflow: auto;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
.page {
  width: 450px;
  height: 30px;
  margin: 30px 0px 0px 200px;
}
.commentsData {
  display: flex;
  justify-content: left;
  align-content: center;
  margin: 30px 0px 0px 30px;
}
.commentsData img {
  width: 50px;
  height: 50px;
  border-radius: 25px;
}
.commentsContainer {
  margin-top: 10px;
  width: 400px;
  font-size: 16px;
  color: #222226;
  line-height: 22px;
  letter-spacing: 1px;
  word-break: break-word;
}
#good {
  width: 25px;
  height: 25px;
  margin-left: 20px;
  cursor: pointer;
}
.discuss {
  display: flex;
  justify-items: left;
  align-content: center;
  padding-left: 10px;
  margin-top: 20px;
}
.discuss img {
  border-radius: 25px;
  margin-top: 10px;
}
.commentData {
  background: rgba(245, 246, 247, 0.8);
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
#commentContent {
  display: block;
  width: 500px;
  background: rgba(248, 249, 251, 0.8);
  border: none;
  padding: 16px;
  border-radius: 4px;
  resize: none;
  height: 158px;
  font-size: 16px;
  line-height: 22px;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  font-family: "SF Pro Display", Roboto, Noto, Arial, "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
}
#commentContent:focus {
  outline: none;
}
.btn1 {
  width: 80px;
  height: 40px;
  margin-left: 400px;
  color: white;
  font-size: 14px;
  text-align: center;
  padding: 0;
  background-color: rgb(4, 137, 239);
}
.comment-enter {
  height: 0px;
}
.comment-enter-to {
  height: 800px;
}
.comment-enter-active {
  transition: all 0.3s linear;
}
.comment-leave {
  height: 800px;
}
.comment-leave-active {
  transition: all 0.3s linear;
}
.comment-leave-to {
  height: 0px;
}
.commentTotal {
  padding: 0px 20px;
  height: 80px;
  line-height: 80px;
  border-bottom: 1px solid #f5f5f5;
  display: flex;
  justify-content: space-between;
}
.commentTotal span {
  font-size: 20px;
  font-weight: 600;
}

.bottomNav {
  margin-top: 20px;
  width: 817px;
  height: 80px;
  background: white;
  position: fixed;
  bottom: 0px;
  margin-left: -10px;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-content: center;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
.bottomNav .action {
  width: 500px;
  height: 50px;
  background-color: white;
}
.leftNav {
  background-color: white;
  width: 300px;
  padding-left: 10px;
  display: flex;
  justify-content: left;
  align-items: center;
}
.leftNav > * {
  margin: 5px 8px;
}
.leftNav span {
  font-size: 18px;
  font-weight: 700;
}
.leftNav img {
  width: 50px;
  height: 50px;
  border-radius: 25px;
}
.rightNav .action .col span {
  font-size: 18px;
  color: rgb(78, 76, 76);
  font-weight: 600;
}
.rightNav .action .col img {
  width: 25px;
  height: 25px;
}
.rightNav .action .col {
  width: 120px;
  display: flex;
  justify-content: left;
  align-items: center;
  cursor: pointer;
}
.datas {
  font-family: "SF Pro Display", Roboto, Noto, Arial, "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  width: 100%;
  background: #f8f8f8;
  border-radius: 10px;
  height: 80px;
  padding-left: 10px;
  margin: 10px 0;
  padding-top: 3px;
}

.container {
  padding-bottom: 10px;
  position: relative;
  display: flex;
}

.head {
  display: flex;
  justify-content: left;
  align-items: center;
}
.head > span,
.content > p {
  font-family: "SF Pro Display", Roboto, Noto, Arial, "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 18px;
  line-height: 25px;
}
.show {
  width: 50%;
  background-color: white;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  padding-bottom: 80px;
  margin: 10px 0px 10px 100px;

  padding-left: 10px;
  padding-top: 10px;
  padding-right: 10px;
}
img {
  width: 40px;
  height: 40px;
  margin-right: 10px;
}
.show div {
  margin-top: 10px;
}

.action {
  height: 20px;
  display: flex;

  align-items: center;
}

.action img {
  width: 20px;
  height: 20px;
  margin-right: 10px;
}

.action span {
  display: block;
}

.action .cow {
  width: 120px;
  display: flex;
  justify-content: left;
  align-items: center;
}

.col span,
.cow span {
  color: #999aaa;
  font-size: 15px;
}
.hot {
  position: absolute;
  left: 80%;
  top: -5%;
}
</style>